import 'package:distribution_mall_flutter/base/base_service.dart';
import 'package:distribution_mall_flutter/constant/constant.dart';
import 'package:distribution_mall_flutter/http/modules/delete_account.dart';
import 'package:distribution_mall_flutter/router/router.gr.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'delete_account_deleting_loading_service.g.dart';

class DeleteAccountDeletingLoadingService extends BaseService {
  String captchaToken, accountName, accountType;

  DeleteAccountDeletingLoadingService(
      super.ref, this.captchaToken, this.accountName, this.accountType);

  @override
  onReady() {
    onDeletion();
  }

  Future<void> onDeletion() async {
    (await DeleteAccountApi.deletion(accountType, accountName, captchaToken))
        .yes((value) {
      appRouter.replace(DeleteAccountDeleteSuccessRoute());
    });
  }
}

@riverpod
DeleteAccountDeletingLoadingService deleteAccountDeletingLoadingService(
    DeleteAccountDeletingLoadingServiceRef ref,
    String captchaToken,
    String accountName,
    String accountType) {
  return DeleteAccountDeletingLoadingService(
      ref, captchaToken, accountName, accountType);
}
